package readers;

import java.util.ArrayList;

import beans.Star;

public class StarsReader extends GenericReader{
	
	protected ArrayList<Star> list = new ArrayList<Star>();
	
	public StarsReader(String path) {
		super(path,true);
	}

	protected String path;
	 ArrayList<Star> array = new ArrayList<Star>();

	
	
	public ArrayList<Star> getArray() {
		return array;
	}

	@Override
	void processLine(String line) {
		 int starID=0;
		 int hip=0;
		 int hd=0;
		 int hr=0;
		 String gliese="";
		 String bayerFlamsteed="";
		 String properName="";
		 double ra=0;
		 double decl=0;
		 double distance=0;
		 double mag=0;
		 double absMag=0;
		 String spectrum="";
		 double colorIndex=0;
		 double x=0;
		 double y=0;
		 double z=0;
		try{
			String [] parts = line.split(",");		
			starID=Integer.parseInt(parts[0].trim().equalsIgnoreCase("")?"0":parts[0].trim());
			hip=Integer.parseInt(parts[1].trim().equalsIgnoreCase("")?"0":parts[1].trim());
			hd=Integer.parseInt(parts[2].trim().equalsIgnoreCase("")?"0":parts[2].trim());
			hr=Integer.parseInt(parts[3].trim().equalsIgnoreCase("")?"0":parts[3].trim());
			gliese=parts[4];
			bayerFlamsteed=parts[5];
			properName=parts[6];
			ra=Double.parseDouble(parts[7].trim());
			decl=Double.parseDouble(parts[8].trim());
			distance=Double.parseDouble(parts[9].trim());
			mag=Double.parseDouble(parts[10].trim());
			absMag=Double.parseDouble(parts[11].trim());
			spectrum=parts[12];
			colorIndex=Double.parseDouble(parts[13].trim().equalsIgnoreCase("")?"0.0":parts[13].trim());

			double azimut =ra*15.0;
			double incl=decl+90.0;
			
			x=distance*Math.sin(incl)*Math.cos(azimut);
			y=distance*Math.sin(incl)*Math.sin(azimut);;
			z=distance*Math.cos(incl);		
			double r =Math.sqrt(x*x+y*y+z*z);
			double delta =(r-distance)/distance;
			
			if(delta>1e-7){
				System.out.println("allert r:"+delta);
			}
		}
		catch (Exception e){
			System.out.println(e);
		}
		
		Star s = new Star(starID, hip, hd, hr, gliese, bayerFlamsteed, properName, ra, decl, distance, mag, absMag, spectrum, colorIndex, x, y, z);
		array.add(s);
	}
	

}
